//index.js

const util = require("../../utils/util");
const WordEntity = require("../beans/WordEntity");

//获取应用实例
var app = getApp()
Page({
    data: {
        input_value: "",
        list:"",
        lodingInfo:"",
        // text:"由于网络原因，第一次查单词稍有延迟，请耐心等待",
        text:"",
        wstart:"",
        wend:"",
        textfalse:"",
        a:"",
        b:"",
        c:"",
        d:""
    },
    onLoad: function() {
        // console.log('onLoad')
    },
    wsearchIput: function(e) {
        this.setData({
            input_value: e.detail.value
        });
        // console.log(this.data.input_value);
    },
    searchWord: function() {
        var that = this;
        this.setData({

        });

        var reg=new RegExp("<li><span>","g");
        var reg1=new RegExp("</span><strong>","g");
        var reg2=new RegExp("</strong></li>","g");
        var reg3=new RegExp("<li><strong>","g");

        wx.request({
            method: 'GET',
            url: "http://api.tianapi.com/txapi/enwords/index?key=fe3550386539024870fb13a253fbcc53&word="+that.data.input_value,
            header: {
                'Content-Type': 'application/json'
            },
            success: function(res) {
                console.log(res.data)
                if(res.data.code == 200){
                    console.log('ressuc',res);
                    that.setData({
                         text: res.data.newslist
                    })
                }else{
                    that.setData({
                        text: res.msg
                    })
                }
            },
            fail: function() {
                that.setData({
                    // text: "搜索失败，请检查您的网络"
                });
                console.log("error");
            },
            complete: function() {
                that.setData({

                })
            }
        })
    },
    favoriteBtn: function(e) {
        let worldTranslate = e.currentTarget.dataset.text[0];
        let wordBooks = wx.getStorageSync(util.wordBook)
        if(wordBooks === null || wordBooks === undefined || wordBooks === '' ) {
            wordBooks = [];
        }
        let entity = new WordEntity();
        entity.setContent(worldTranslate.content);
        entity.setWord(worldTranslate.word);
        wordBooks.push(entity);
        wx.setStorageSync(util.wordBook,wordBooks);
    }


})
